package site.jlopen.components.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import lombok.Data;

@Data
public class GraphListInfo {
	
	private String id;
	
	private String title;
	
	private String code;
	
	private int sort;
	
	private List<String> sources;
	
	private List<String> ports;
	
	private List<String> targets;
	
	private List<String> sourceTexts;
	
	private List<String> targetTexts;
	
	public GraphListInfo addPort(String portId) {
		if(null == ports) {
			ports = new ArrayList<String>();
		}
		ports.add(portId);
		return this;
	}
	
	public GraphListInfo addSource(String sourceId) {
		if(null == sources) {
			sources = new ArrayList<String>();
		}
		sources.add(sourceId);
		return this;
	}
	
	public GraphListInfo addTarget(String targetId) {
		if(null == targets) {
			targets = new ArrayList<String>();
		}
		targets.add(targetId);
		return this;
	}
	
	public GraphListInfo addSourceText(String sourceText) {
		if(null == sourceTexts) {
			sourceTexts = new ArrayList<String>();
		}
		sourceTexts.add(sourceText);
		return this;
	}
	
	public GraphListInfo addTargetText(String targetText) {
		if(null == targetTexts) {
			targetTexts = new ArrayList<String>();
		}
		targetTexts.add(targetText);
		return this;
	}
	
	@Override
    public boolean equals(Object o) {
        if (this == o) return true; // 自反性：如果两个引用指向同一个对象，则它们相等
        if (o == null || getClass() != o.getClass()) return false; // 一致性：任何对象与null都不相等，且只比较相同类型的对象
 
        GraphListInfo yourClass = (GraphListInfo) o;
 
        // 使用Objects.equals来比较字符串和列表，这样可以避免空指针异常
		return /*sort == yourClass.sort &&*/
                Objects.equals(id, yourClass.id) &&
                Objects.equals(title, yourClass.title) &&
                Objects.equals(code, yourClass.code) &&
                Objects.equals(sources, yourClass.sources) &&
                Objects.equals(targets, yourClass.targets) &&
                Objects.equals(sourceTexts, yourClass.sourceTexts) &&
                Objects.equals(targetTexts, yourClass.targetTexts);
    }
 
    // 通常还需要重写hashCode方法，以保证equals和hashCode的一致性
    @Override
    public int hashCode() {
		return Objects.hash(id, title, code, /*sort,*/ sources, targets, sourceTexts, targetTexts);
    }
}
